<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>图片上传</title>
</head>
<body>
  <input type="file" id="upload" />
  <script>
    const upload = document.getElementById('upload')
    upload.addEventListener('change', function () {
      // 获取到上传的file对象
      const file = upload.files[0]
      // 声明FormData对象
      const formData = new FormData()
      // 添加实例属性file
      formData.append('file', file)
      console.log('formData', formData, file);
      fetch('http://localhost:7002/api/upload', {
        method: 'POST',
        body: formData,
        headers: {
          'authorization': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Ilp5aCIsImlkIjoxLCJleHAiOjE2NzEwMDg5ODUsImlhdCI6MTY3MDkyMjU4NX0.Dic_jFBmLlC61iBXZon-dfuYUgLXb8sm5X6fu0dyQeY'
        }
      }).then(res => res.json())
        .then(res => {
          console.log(res)
        })
    })
  </script>
</body>
</html>
